package filter;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;

/**
 * 过滤消息生产者-sql方式
 */
public class FilterSqlProducer {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer("FilterSqlProducer");
        producer.setNamesrvAddr("");
        producer.start();
        String[] tags = new String[]{"TagA","TagB","TagC"};
        for (int i=0;i<10;i++){
            Message message = new Message("Filter",tags[i%tags.length],(tags[i % tags.length]+"_FileterSqlProducer").getBytes(StandardCharsets.UTF_8));
            message.putUserProperty("ay","1");
            SendResult sendResult = producer.send(message);
            System.out.println(tags[i % tags.length]+"ay:"+i+"_消息发送成功%s%n"+sendResult);

        }
        producer.shutdown();
    }
}
